package kbs.scm
{
    public class AList extends Base
    {
        public function AList(v:Array)
        { m_l = v; }

        public function car():Base
        { return m_l[0] as Base; }

        public function cdr():AList
        { return nth(1); }

        public function nth(start:int):AList
        {
            var ret:AList = new AList([]);
            // Array.splice is destructive...
            for (var i:int = start; i<m_l.length; i++) {
                ret.append(m_l[i]);
            }
            return ret;
        }

        public function append(el:Base):AList
        {
            m_l.push(el);
            return this;
        }

        public function get(i:int):Base
        { return m_l[i] as Base; }

        public function length():int
        { return m_l.length; }

        override public function pprint():String
        {
            var ret:String = "(";
            for (var i:int =0; i<m_l.length; i++) {
                ret += (m_l[i] as Base).pprint();
                ret += " ";
            }
            ret += ")";
            return ret;
        }


        private var m_l:Array;
    }
}
